package com.homegoods.classify.persenter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.classify.R;
import com.homegoods.classify.model.BrandModel;
import com.homegoods.classify.model.ClassifyModel;
import com.homegoods.classify.model.RightModel;
import com.homegoods.classify.view.ClassifyView;
import com.kedll.library.mvp.BasePresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * add shibo.zheng
 * 19/06/20
 * 分类fragment的presenter
 */
public class ZPClassifyPresenter extends BasePresenter<ClassifyView> {
    private List<ClassifyModel> classifyModels;
    private List<Fragment> fragments;
    private List<String> titles;


    public ZPClassifyPresenter(ClassifyView view) {
        super(view);
        initClassifyData();
        loadData(classifyModels);
    }

    private void loadData(List<ClassifyModel> models) {
        if (models.size() == 0) {
            return;
        }
        fragments = new ArrayList<>();
        titles = new ArrayList<>();
        for (int i = 0; i < models.size(); i++) {
            ClassifyModel classifyModel = models.get(i);
            titles.add(classifyModel.getLeftTitle());
            Fragment fragment;
            if ("品牌".equals(classifyModel.getLeftTitle())) {    //品牌
                fragment = (Fragment) ARouter.getInstance().build(ARouterPath.PATH_ZP_CLASSIFY_BRAND).navigation();
            } else {    //other
                fragment = (Fragment) ARouter.getInstance().build(ARouterPath.PATH_ZP_CLASSIFY_OTHER).navigation();
            }
            Bundle bundle = new Bundle();
            bundle.putSerializable("classifyModel", classifyModel);
            fragment.setArguments(bundle);  //将classifyModel传入到对应的fragemnt中去
            fragments.add(fragment);
        }
        mView.initZPViewPager(fragments, titles);
    }

    private void initClassifyData() {
        classifyModels = new ArrayList<>();
        ClassifyModel model1 = new ClassifyModel();

        model1.setLeftTitle("品牌");                         // 1

        List<BrandModel> brandModels = new ArrayList<>();       //  2
        BrandModel brandModel = new BrandModel();
        brandModel.setBrandTitle("运动户外");                    //3
        RightModel rightModel1 = new RightModel(R.mipmap.yundong, "");
        RightModel rightModel2 = new RightModel(R.mipmap.yundong, "");
        RightModel rightModel3 = new RightModel(R.mipmap.yundong, "");
        RightModel rightModel4 = new RightModel(R.mipmap.yundong, "");
        List<RightModel> rightModels = new ArrayList<>();
        rightModels.add(rightModel1);
        rightModels.add(rightModel2);
        rightModels.add(rightModel3);
        rightModels.add(rightModel4);
        brandModel.setRightModels(rightModels);
        brandModels.add(brandModel);

        model1.setBrandModels(brandModels);                                //  1

        BrandModel brandModel1 = new BrandModel();
        brandModel1.setBrandTitle("钟表配饰");
        RightModel rightModela = new RightModel(R.mipmap.yundong, "");
        RightModel rightModelb = new RightModel(R.mipmap.yundong, "");
        RightModel rightModelc = new RightModel(R.mipmap.yundong, "");
        RightModel rightModeld = new RightModel(R.mipmap.yundong, "");
        List<RightModel> rightModels1 = new ArrayList<>();
        rightModels1.add(rightModela);
        rightModels1.add(rightModelb);
        rightModels1.add(rightModelc);
        rightModels1.add(rightModeld);
        brandModel1.setRightModels(rightModels1);
        brandModels.add(brandModel1);
        model1.setBrandModels(brandModels);

        classifyModels.add(model1);

        ClassifyModel model2 = new ClassifyModel();
        model2.setLeftTitle("热销男鞋");
        RightModel rightModel11 = new RightModel(R.mipmap.phone, "哇哈哈");
        RightModel rightModel22 = new RightModel(R.mipmap.phone, "加多宝");
        RightModel rightModel33 = new RightModel(R.mipmap.phone, "雪碧");
        RightModel rightModel44 = new RightModel(R.mipmap.phone, "可乐");
        List<RightModel> rightModels2 = new ArrayList<>();
        rightModels2.add(rightModel11);
        rightModels2.add(rightModel22);
        rightModels2.add(rightModel33);
        rightModels2.add(rightModel44);
        model2.setRightModels(rightModels2);
        classifyModels.add(model2);

        ClassifyModel model3 = new ClassifyModel();
        model3.setLeftTitle("宅品家装");
        RightModel rightModel111 = new RightModel(R.mipmap.yundong, "凉鞋");
        RightModel rightModel222 = new RightModel(R.mipmap.phone, "皮鞋");
        RightModel rightModel333 = new RightModel(R.mipmap.yundong, "帆布鞋");
        RightModel rightModel444 = new RightModel(R.mipmap.phone, "高跟鞋");
        List<RightModel> rightModels3 = new ArrayList<>();
        rightModels3.add(rightModel111);
        rightModels3.add(rightModel222);
        rightModels3.add(rightModel333);
        rightModels3.add(rightModel444);
        model3.setRightModels(rightModels3);
        classifyModels.add(model3);

        ClassifyModel model4 = new ClassifyModel();
        model4.setLeftTitle("宅品美食");
        RightModel rightModel5 = new RightModel(R.mipmap.phone, "休闲鞋");
        RightModel rightModel6 = new RightModel(R.mipmap.yundong, "女鞋");
        RightModel rightModel7 = new RightModel(R.mipmap.phone, "男鞋");
        RightModel rightModel8 = new RightModel(R.mipmap.phone, "新品推荐");
        List<RightModel> rightModels4 = new ArrayList<>();
        rightModels4.add(rightModel5);
        rightModels4.add(rightModel6);
        rightModels4.add(rightModel7);
        rightModels4.add(rightModel8);
        model4.setRightModels(rightModels4);
        classifyModels.add(model4);

    }

}
